<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/template/common/taglibs.jspf" %>
<es:contentHeader/>

<t:base type="jquery,jquery-ui-bootstrap:bootstrap,jquery-ui-bootstrap:jquery-ui,query-ui-bootstrap:jquery.layout,jquery-ui-bootstrap:font-awesome"></t:base>
<t:base type="jquery-ui-bootstrap:jquery.blockUI,jquery-ui-bootstrap:bootstrap.file-input,bootstrap-datetimepicker,nicescroll,jqueryValidate,application,common,datePicker"></t:base>


<%--<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/plug-in/bootstrap/css/bootstrap.min.css">--%>


<style type="text/css">
    .error {
        color: red;
    }
</style>

<form id="editForm" method="post">


    <table class="table table-bordered " style="background-color: whitesmoke">

        <tr>
            <th colspan="6">
                提单信息栏
            </th>
        </tr>

        <tr>
            <th>销售订单号</th>
            <td>${saleOrderHeader.saleordercode}</td>
            <th>客户名称</th>
            <td>${saleOrderHeader.custfullname}</td>
        </tr>

        <tr>
            <th>业务员</th>
            <td>${saleOrderHeader.salemanname}</td>
            <th>目的港</th>
            <td>${saleOrderHeader.destport}</td>
            <th>包装要求</th>
            <td>${saleOrderHeader.packing}</td>
        </tr>

        <tr>
            <th>备注</th>
            <td colspan="5">
                ${saleOrderHeader.remark}
            </td>
        </tr>

        <tr>
            <th>装车日期</th>
            <td><input type="text" name="carryDate" value="<fmt:formatDate value="${m.carryDate}" pattern="yyyy-MM-dd"/>" onclick="wdate()"></td>
            <input type="hidden" name="saleOrderCode" value="${saleOrderHeader.saleordercode}">
        </tr>
    </table>


    <div style="clear: both"></div>

    <div class="table-responsive">
        <table class="table table-bordered table-hover" style="white-space: nowrap">
            <thead>
            <tr>
                <th colspan="14">商品装箱信息栏</th>
            </tr>
            <tr>
                <th>产品编码</th>
                <%--<th>品牌</th>--%>
                <th>规格描述</th>
                <%--<th>装箱量</th>--%>
                <%--<th>派车箱量</th>--%>
                <%--<th>申请数量</th>--%>
                <%--<th>剩余数量</th>--%>
                <%--<th>可用库存</th>--%>
                <th>分箱数量</th>
                <th>填箱规格</th>
                <th>甩箱规格</th>
                <th>标签</th>
                <%--<th>备注</th>--%>
            </tr>
            </thead>

            <c:forEach items="${saleOrderItems}" var="m">
                <tr>

                    <td>${m.saleorderitemcode}</td>
                    <%--<td>${m.brand}</td>--%>
                    <td>${m.standard}</td>
                    <%--<td>${m.packingqty}</td>--%>
                    <%--<td>${m.containerqty}</td>--%>
                    <%--<td>${m.quantity}</td>--%>
                    <%--<td>${hasNotDeliverCount[m.saleorderitemcode]}</td>--%>
                    <%--<td>可用库存</td>--%>
                    <td>${m.planquty}</td>
                    <th>${m.fillsigna}</th>
                    <th>${m.fillsignb}</th>
                    <th>标签</th>
                    <%--<th>${m.contractremark}</th>--%>


                </tr>
            </c:forEach>
        </table>
    </div>



    <div class="table-responsive">
        <table class="table table-bordered table-hover" style="white-space: nowrap">
            <thead>
            <tr>
                <th colspan="14">海关规格信息栏</th>
            </tr>
            <tr>
                <th>产品编码</th>
                <th>分箱数量</th>
            </tr>
            </thead>

            <c:forEach items="${customsStandardMap}" var="entry">
                <tr>
                    <td>${entry.key}</td>
                    <td>${entry.value}</td>
                </tr>
            </c:forEach>
        </table>
    </div>


    <c:if test="${not empty handbookUsedDetails}">
        <div class="table-responsive">
            <table id="handBookUsedTable" class="table table-bordered table-hover" style="white-space: nowrap">
                <thead>
                    <tr>
                        <th colspan="14">手册使用明细信息栏</th>
                    </tr>

                </thead>


                <tr>
                    <th>序号</th>
                    <th>使用时间</th>
                    <th>手册编码</th>
                    <th>规格</th>
                    <th>本次冻结量</th>
                </tr>


                <c:forEach items="${handbookUsedDetails}" var="detail" varStatus="i">
                    <tr>
                        <td>${i.count}</td>
                        <td><fmt:formatDate value="${detail.createDate}" pattern='yyyy年MM月dd日 hh:mm:ss'/></td>
                        <td>${detail.deliveryId}</td>
                        <td>${detail.specifications}</td>
                        <td>${detail.usedQty}</td>
                    </tr>
                </c:forEach>

            </table>
        </div>
    </c:if>

    <c:if test="${empty handbookUsedDetails}">
        <div class="table-responsive">
            <table id="handBookTable" class="table table-bordered table-hover" style="white-space: nowrap">
                <thead>
                <tr>
                    <th colspan="14">手册明细信息栏</th>
                </tr>
                    <%--<tr>--%>
                    <%--<th>手册编码</th>--%>
                    <%--<th>本次冻结量</th>--%>
                    <%--</tr>--%>
                </thead>
                <tr>
                    <td></td>
                    <td>序号</td>
                    <td></td>
                    <td></td>
                    <c:forEach items="${customsStandardMap}" var="entry">
                        <td>${entry.key}</td>
                        <td>${entry.value}</td>
                        <%--<th>手册编码</th>--%>
                        <%--<th>本次冻结量</th>--%>

                    </c:forEach>
                </tr>

                <tr>
                    <td></td>
                    <td>-1</td>
                    <td>手册编码</td>
                    <td>本次冻结量</td>
                    <c:forEach items="${customsStandardMap}" var="entry">
                        <th>可用量</th>
                        <th>本次冻结量</th>
                    </c:forEach>
                </tr>


                <c:forEach items="${matchHandBookList}" var="matchHandBook" varStatus="i">
                    <tr>
                        <td class="check">
                            <input type="checkbox" name="customerHandBookId" value="${matchHandBook.customerHandBookId}" />
                        </td>
                        <td>${i.count}</td>
                        <td>${matchHandBook.customerHandBookId}</td>

                        <c:if test="${i.count==1}">
                            <td>${customsStandardValuesTotal}</td>
                        </c:if>
                        <c:if test="${i.count!=1}">
                            <td></td>
                        </c:if>

                        <c:forEach items="${matchHandBook.map}" var="entry" varStatus="j">
                            <td>${entry.value}</td>

                            <c:if test="${i.count==1}">
                                <td><input type="text" name="usedCount" value="${customsStandardValues[j.count-1]}"></td>
                            </c:if>
                            <c:if test="${i.count!=1}">
                                <td></td>
                            </c:if>
                        </c:forEach>

                    </tr>
                </c:forEach>

            </table>
        </div>
    </c:if>




    <div class="control-group left-group">
        <div>

            <c:if test="${empty handbookUsedDetails}">
                <button type="submit" id="sub" class="btn btn-primary">
                    <i class="${icon}"></i>
                        商检确认
                </button>
            </c:if>

            <a href="javascript:self.location=document.referrer;" class="btn">
                <i class="icon-reply"></i>
                返回
            </a>
        </div>


    </div>


    <input type="hidden" name="customerHandBookIdOnlyOne" id="customerHandBookIdOnlyOne">
    <input type="hidden" name="deliveryId" id="deliveryId" value="${deliveryId}">

</form>


<es:contentFooter/>


<script type="text/javascript">


    $(function () {
        $("#editForm").validate({
            rules: {
                useCount: {
                    required: true
                }
            },
            messages: {
                useCount: {
                    required: "请输入数量"
                }
            }
        });

        $("#editForm").submit(function () {
            var flag = $("#editForm").valid();
            if (!flag) {
                return false;
            }

            var checkbox = $.table.getAllSelectedCheckbox($("#handBookTable"));
            if(!checkbox.length) {
                var id = checkbox.val();

                alert("没有选中手册！");
                return false;
            }
            var id = checkbox.val();
            $("#customerHandBookIdOnlyOne").val(id);

        });

        $("#confirm").click(function () {
            var deliveryId = $("#deliveryId").val();
            var url = ctx + "/admin/delivery/"+deliveryId+"/confirm";
            window.location.href = url;
        });

        $("#refuse").click(function () {
            var deliveryId = $("#deliveryId").val();
            var url = ctx + "/admin/delivery/"+deliveryId+"/refuse";

            var title = "撤回";
            var tip = "请输入撤回原因";
            $.app.confirm({
                title: title,
                message : tip + "<br/><textarea id='reason' style='width: 300px;height: 50px;'></textarea>",
                ok : function() {
                    var reason = $("#reason").val();
                    if(reason) {
                        window.location.href = url + "?reason=" + reason;
                    }
                }
            });
        });

    });

</script>